<?php


namespace app\command;

use app\admin\model\base\Student;
use app\admin\model\base\StudentPaper;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class Paper  extends Command
{
    protected function configure()
    {
        $this->setName('Paper')->setDescription('到期一分钟自动结束考试');
    }

    protected function execute(Input $input, Output $output)
    {
       $list = StudentPaper::where('status','=',0)->with(['paper'])->select()->toArray();
       if(!empty($list)){
           $arr = [];
           foreach ($list as $value){
               $start_times = strtotime($value['start_time']);
               if($start_times + ($value['paper']['time'] * 61) > time()){
                   //学生考试超时，自动提交试卷
                   $arr[] = $value['id'];
                   //交卷
                   $info = StudentPaper::where('id','=',$value['id'])->find();
                   $take_time = (time() - strtotime($info->start_time)) / 60;
                   $res = StudentPaper::where('id','=',$value['id'])->update(['status'=>1,'end_time'=>date('Y-m-d H:i:s',time()),'take_time'=>$take_time]);
               }
           }
           if(!empty($arr)){

           }
       }
    }
}